/**
* 头部菜单
*/
<template>
  <el-menu class="el-menu-demo" mode="horizontal" background-color="#334157" text-color="#fff" active-text-color="#fff">
    <el-submenu index="2" style="float: right">
      <!-- <template slot="title">{{user.userRealName}}</template> -->
      <template slot="title">超级管理员</template>
      <el-menu-item @click="edit()" index="2-2">设置登录密码</el-menu-item>
      <el-menu-item @click="exit()" index="2-3">退出</el-menu-item>
    </el-submenu>
  </el-menu>
</template>
<script>
import publicApi from "@/api/publicApi";
import manageApi from "@/api/manage"
import Cookies from "js-cookie";
export default {
  name: 'TopNav',
  data() {
    return {
      collapsed: true,
      // imgshow: require('../assets/img/show.png'),
      // imgsq: require('../assets/img/sq.png'),
      user: {},
    }
  },
  // 创建完毕状态(里面是操作)
  created() {
    this.user = JSON.parse(localStorage.getItem('userdata'))
  },
  methods: {
    // 退出登录
    exit() {
      this.$confirm('退出登录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        manageApi.adminLogout().then(res =>{
          Cookies.remove("Token");
          this.$router.push("/login");
          this.$message.success("退出成功！")
        })
      }).catch(() => {
        this.$message({
          type: 'info',
              message: '已取消'
        })
      })
    },
    edit(){
      this.$prompt('请输入要修改后的密码', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
      }).then(({ value }) => {
        manageApi.editAdminPwd({password:value}).then(res =>{
          this.$message.success("设置成功！")
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        });
      });
    }
  }
}
</script>
<style scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
}
.submenu {
  float: right;
}
.buttonimg {
  height: 60px;
  background-color: transparent;
  border: none;
}
.showimg {
  width: 26px;
  height: 26px;
  position: absolute;
  top: 17px;
  left: 17px;
}
.showimg:active {
  border: none;
}
</style>
